nsc_prospectives = read.csv("./Intern Dataset.csv",header = TRUE)
#str(nsc_prospectives)
#prospectives_from_usl = nsc_prospectives[nsc_prospectives$league=="USL Championship (USA)",]
prospectives_from_mls = nsc_prospectives[nsc_prospectives$league=="MLS (USA)",]
#other_prospectives = nsc_prospectives[nsc_prospectives$league==" (USA)",]
# Gathering players to be filled in the reserve roster spot.
#prospectives_from_usl = prospectives_from_usl[prospectives_from_usl$Age<23,]
suppressMessages(library("htmltab"))
salary_table = htmltab("https://www.americansocceranalysis.com/sept-13-2019",which = 7)
salary_table$`Base Salary`= as.double(gsub("[\\$,]","",salary_table$`Base Salary`))
salary_table$`Guaranteed Compensation`= as.double(gsub("[\\$,]","",salary_table$`Guaranteed Compensation`))
#fix(salary_table)
# MLS players with Guaranteed Compensation less than $400K.
mls_players_under_400k = salary_table[salary_table$`Guaranteed Compensation`<= 400000.00,]
remove(salary_table)
#
# usl_foreign_players = htmltab::htmltab("https://www.transfermarkt.co.in/usl-pro/gastarbeiter/wettbewerb/USL/saison_id/gesamt",which = 4)
#
#
# usl_foreign_players$Player = gsub("á","á",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("é","é",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("ç","ç",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Ã","í",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("íº","ú",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("í³","ó",usl_foreign_players$Player)
#
# # usl_foreign_players$Player = gsub("á","a",usl_foreign_players$Player)
# # usl_foreign_players$Player = gsub("é","e",usl_foreign_players$Player)
# # usl_foreign_players$Player = gsub("ç","c",usl_foreign_players$Player)
# # usl_foreign_players$Player = gsub("Ã","i",usl_foreign_players$Player)
# # usl_foreign_players$Player = gsub("iº","u",usl_foreign_players$Player)
# # usl_foreign_players$Player = gsub("í³","o",usl_foreign_players$Player)
#
#
# usl_foreign_players$Player = gsub("Goalkeeper","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Right-Back","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Centre-Back","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Left-Back","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Defensive Midfield","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Right Midfield","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Central Midfield","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Left Midfield","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Attacking Midfield","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Right Winger","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Centre-Forward","",usl_foreign_players$Player)
# usl_foreign_players$Player = gsub("Left Winger","",usl_foreign_players$Player)
suppressMessages(library("dplyr"))
suppressMessages(library("tidyr"))
# usl_foreign_players = usl_foreign_players %>% separate(Player,c("firstName","lastName")," ",extra = "merge" )
#usl_foreign_players_copy = usl_foreign_players
prospectives_from_usl = read.csv("./u23_players_2019_with_nationalities.csv",header = TRUE,stringsAsFactors=FALSE)
prospectives_from_mls = left_join(prospectives_from_mls,mls_players_under_400k,by = c("firstName" = "First Name", "lastName" = "Last Name"))
prospectives_from_mls = na.omit(prospectives_from_mls)
remove(mls_players_under_400k)
mls_players_2019_nationalities <- read.csv("mls_players_2019_nationalities.csv",header = TRUE)
prospectives_from_mls = left_join(prospectives_from_mls,mls_players_2019_nationalities,by = c("firstName"="firstName","lastName"="lastName"))
remove(mls_players_2019_nationalities)
addMetrics = function(df){
xGperShot = round(df$xG/df$Shot,2)
xAper90 = round((df$xA/df$Min)*90,2)
xGper90 = round((df$xG/df$Min)*90,2)
xAGper90 = round(xAper90 + xGper90,2)
Shotsper90 = round((df$Shot/df$Min)*90,2)
Goalsper90 = round((df$Goal/df$Min)*90,2)
Asstper90 = round(df$Ast/df$Min*90,2)
chancesper90 = round((df$ChncOpnPl+df$ChncSetPl)/df$Min*90,2)
xAGperChance = round((df$xA + df$xG)/(df$ChncOpnPl+df$ChncSetPl),2)
Intper90 = round(df$Int/df$Min*90,2)
Tklper90 = round(df$Tckl/df$Min*90,2)
MinperAG = round(df$Min/(df$Goal+df$Ast),2)
TklAcc = round(df$Tckl/df$TcklAtt*100,2)
df$X1v1. = as.numeric(gsub("%","",df$X1v1.))/100
df = cbind(df,MinperAG,xAper90,xGper90,xAGper90,Shotsper90,Goalsper90,Asstper90,chancesper90,xAGperChance,xGperShot,Intper90,Tklper90,TklAcc)
return(df)
}
usl = prospectives_from_usl#[prospectives_from_usl$Position=="Centre Forward",]
usl = addMetrics(usl)
mls = prospectives_from_mls#[prospectives_from_mls$"Position.x"=="Centre Forward",]
mls = addMetrics(mls)
mls$Country[mls$player=="M. Azira"]="Uganda"
mls$Country[mls$player=="Z. Brault-Guillard"]="Cuba"
mls$Country[mls$lastName=="Blessing"]="USA"
library(plotly)
data = mls[mls$Position.x=="Centre Forward",]
data$player <- factor(data$player, levels = data$player[order(data$Goalsper90)])
#m =
plot_ly(data, color = I("gray70"),
text = ~paste(player,'<br>',"MLS",
'<br><b>xG/90:</b> ',round(xGper90,2),
'<br><b>Goals/90:</b> ',round(Goalsper90,2)),
hoverinfo = 'text'
) %>%
add_segments(x = ~xGper90, xend = ~Goalsper90, y = ~player, yend = ~player, showlegend = FALSE) %>%
add_markers(x = ~xGper90, y = ~player, name = "xG/90", color = I("orange")) %>%
add_markers(x = ~Goalsper90, y = ~player, name = "Goals/90", color = I("blue")) %>%
layout(
title = "xG/90 and G/90 - MLS CFs",
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "xG/90 <-----> G/90",showgrid = FALSE,zeroline=FALSE),
yaxis = list(title = "Centre-Forwards"),
margin = list(l = 65),legend = list(orientation = 'v')
)
data = usl[usl$Position=="Centre Forward",]
data$player <- factor(data$player, levels = data$player[order(data$Goalsper90)])
#u =
plot_ly(data, color = I("gray70"),
text = ~paste(player,'<br>',"USL",
'<br><b>xG/90:</b> ',round(xGper90,2),
'<br><b>Goals/90:</b> ',round(Goalsper90,2)),
hoverinfo = 'text'
) %>%
add_segments(x = ~xGper90, xend = ~Goalsper90, y = ~player, yend = ~player, showlegend = FALSE) %>%
add_markers(x = ~xGper90, y = ~player, name = "xG/90", color = I("orange")) %>%
add_markers(x = ~Goalsper90, y = ~player, name = "Goals/90", color = I("blue")) %>%
layout(
title = "xG/90 and G/90 - USL CFs",
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "xG/90 <-----> G/90",showgrid = FALSE,zeroline=FALSE),
yaxis = list(title = "Centre-Forwards"),
margin = list(l = 65),legend = list(orientation = 'v')
)
data = usl[usl$Position=="Centre Forward",c("xGper90","Goalsper90","player","league")]
data = rbind(mls[mls$Position.x=="Centre Forward",c("xGper90","Goalsper90","player","league")],data)
data$player <- factor(data$player, levels = data$player[order(data$Goalsper90)])
#u =
plot_ly(data, color = I("gray70"),
text = ~paste(player,'<br>',
ifelse(data$league=="MLS (USA)",
paste("MLS"),
paste("USL")),
'<br><b>xG/90:</b> ',round(xGper90,2),
'<br><b>Goals/90:</b> ',round(Goalsper90,2)),
hoverinfo = 'text'
) %>%
add_segments(x = ~xGper90, xend = ~Goalsper90, y = ~player, yend = ~player, showlegend = FALSE) %>%
add_markers(x = ~xGper90, y = ~player, name = "xG/90", color = I("orange")) %>%
add_markers(x = ~Goalsper90, y = ~player, name = "Goals/90", color = I("blue")) %>%
layout(
title = "xG/90 and G/90 - MLS and USL CFs",
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "xG/90 <-----> G/90",showgrid = FALSE,zeroline=FALSE),
yaxis = list(title = "Centre-Forwards "),
margin = list(l = 65),legend = list(orientation = 'v')
)
plot_ly(data = mls[mls$Position.x=="Centre Forward",],
x = ~xGperShot,
y = ~Shotsper90, type = "scatter",mode = "markers",text = ~paste(player,'<br>',Position.x,'<br><b>Goals/90:</b> ',round(Goalsper90,2)),hoverinfo = 'text',
color = ~Goalsper90,size = ~Goalsper90,
marker = list(#size = 10,
#color = ~Goalsper90,
line = list(color = 'rgba(152, 0, 0, .8)',
width = 1))
) %>%
layout(title = 'Shot Quality vs Shot Quantity (MLS CFs)',
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "Shot Quality (xG/Shot)",linecolor = toRGB("black"),showgrid = FALSE),
yaxis = list(title = "Shot Quantity (Shots/90)",linecolor = toRGB("black"),showgrid = FALSE)
)
plot_ly(data = usl[usl$Position=="Centre Forward",],
x = ~xGperShot, y = ~Shotsper90,
type = "scatter",mode = "markers",
text = ~paste(player,'<br>',Position,'<br><b>Goals/90:</b> ',round(Goalsper90,2)),
hoverinfo = 'text',
colors = "RdYlGn", color = ~Goalsper90,size = ~Goalsper90,
marker = list(color = ~Goalsper90,
line = list(color = 'black',width = 1))
) %>%
layout(title = 'Shot Quality vs Shot Quantity (USL CFs)',
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "Shot Quality (xG/Shot)",linecolor = toRGB("black"),showgrid = FALSE),
yaxis = list(title = "Shot Quantity (Shots/90)",linecolor = toRGB("black"),showgrid = FALSE)
)
data = mls[mls$Position.x=="Centre Forward",c("league","xGperShot","Shotsper90","player","Goalsper90")]
data = rbind(usl[usl$Position=="Centre Forward",c("league","xGperShot","Shotsper90","player","Goalsper90")],data)
plot_ly(data ,
x = ~xGperShot, y = ~Shotsper90,
type = "scatter",mode = "markers",
text = ~paste(player,'<br>',
ifelse(data$league=="MLS (USA)",
paste("MLS"),
paste("USL")),
'<br><b>Goals/90:</b> ',round(Goalsper90,2)),
hoverinfo = 'text',
color = ~Goalsper90,size = ~Goalsper90,colors = "RdYlGn",
marker = list(line = list(color = 'rgba(0, 0, 0, .8)',width = 1))
) %>%
layout(title = 'Shot Quality vs Shot Quantity (MLS + USL CFs)',
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "Shot Quality (xG/Shot)",linecolor = toRGB("black"),showgrid = FALSE),
yaxis = list(title = "Shot Quantity (Shots/90)",linecolor = toRGB("black"),showgrid = FALSE)
)
library(fmsb)
radarCF = function(data)
{
#print(data)
#plot.new()
par(mar = c(1,1,1.3,1))
#par(mai = c(1,1,1,1))
par(mfrow=c(9,4))
plot.new()
plot.new()
plot.new()
plot.new()
for(i in 1:nrow(data))
{
data1 <- rbind(apply(data[c("xGperShot","Shotsper90","X1v1.","xAGper90","xAGperChance","Goalsper90")],2,max) ,
apply(data[c("xGperShot","Shotsper90","X1v1.","xAGper90","xAGperChance","Goalsper90")],2,min) ,
data[i,c("xGperShot","Shotsper90","X1v1.","xAGper90","xAGperChance","Goalsper90")])
#print(data$player[i])
#print(data1)
radarchart(data1, axistype=1 ,
# Orange for Domestic , Blue for International Players
pcol = ifelse(data$Country[i]=="USA",rgb(0.98,0.55,0.01,0.9),rgb(0.1,0.1,0.9,0.7)),
pfcol = ifelse(data$Country[i]=="USA",rgb(0.98,0.55,0.01,0.3),rgb(0.1,0.2,0.9,0.3)),
#custom polygon
plwd=2 ,
vlabels =c("xG/Shot","Shots/90","1v1Acc","xAG/90","xAG/Chan","Goals/90"),vlcex=1 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="brown", caxislabels= NULL, calcex= 0.6,#, cglwd=0.2,
#custom labels
title = ifelse(data$league[i]=="MLS (USA)",
paste(data$player[i],"(MLS)"),
paste(data$player[i],"(USL)")),
centerzero = TRUE
)
}
mtext("Centre Forwards - Radar Chart",side=3,outer=TRUE,padj=5,cex = 3)
}
CF = rbind(usl[usl$Position=="Centre Forward",c("player","league","Country","xGperShot","Shotsper90","xAGperChance","Goalsper90","xAGper90","X1v1.")]
,mls[mls$Position.x=="Centre Forward",c("player","league","Country","xGperShot","Shotsper90","xAGperChance","Goalsper90","xAGper90","X1v1.")])
radarCF(CF)
# xAG/90 vs Chances/90 (MLS CMs)
plot_ly(data = mls[mls$Position.x=="Central Midfielder",],
x = ~xAGper90,
y = ~chancesper90, type = "scatter",mode = "markers",
text = ~paste(player,'<br>',Position.x,'<br><b>Passing Acc:</b> ',round(Pass.,2)),
hoverinfo = 'text',
color = ~Pass.,size = ~Pass.,
marker = list(line = list(color = 'rgba(152, 0, 0, .8)',width = 1))
) %>%
layout(title = 'xAG/90 vs Chances/90 (MLS CMs)',
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "Expected Contributions Per Match (xAG/90)",
linecolor = toRGB("black"),zeroline = FALSE),
yaxis = list(title = "Chances Created Per Match (Chances/90)",
linecolor = toRGB("black"),zeroline = FALSE))
data = mls[mls$Position.x=="Central Midfielder",]
data = rbind(data,mls[mls$Position.x=="Centre Attacking Midfielder",])
data = rbind(data,mls[mls$Position.x=="Defensive Midfielder",])
plot_ly(
data = usl[usl$Position=="Central Midfielder",],
x = ~xAGper90,
y = ~chancesper90, type = "scatter",mode = "markers",
text = ~paste(player,'<br>',Position,'<br><b>Passing Acc:</b> ',round(Pass.,2)),
hoverinfo = 'text',
color = ~Pass.,colors = "RdYlGn",size = ~Pass.,
marker = list(line = list(color = 'rgba(152, 0, 0, .8)',width = 1))
) %>%
layout(title = 'xAG/90 vs Chances/90 (USL CMs)',
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
xaxis = list(title = "Expected Contributions Per Match (xAG/90)",
linecolor = toRGB("black"),zeroline = FALSE),
yaxis = list(title = "Chances Created Per Match (Chances/90)",
linecolor = toRGB("black"),zeroline = FALSE))
# xAGperChance vs Chances/90 (All CMs) (Attacking CMs)
data = usl[usl$Position=="Central Midfielder",c("player","xAGperChance","chancesper90","Pass.","league")]
data = rbind(mls[mls$Position.x=="Central Midfielder",c("player","xAGperChance","chancesper90","Pass.","league")],data)
plot_ly(
data ,
x = ~xAGperChance,
y = ~chancesper90, type = "scatter",mode = "markers",
text = ~paste(player,'<br>',
ifelse(data$league=="MLS (USA)",
paste("MLS"),
paste("USL"))
,'<br><b>Passing Acc:</b> ',round(Pass.,2)),
hoverinfo = 'text',
color = ~Pass.,colors = "RdYlGn",size = ~Pass.,
marker = list(line = list(color = 'rgba(152, 0, 0, .8)',width = 1))
) %>%
layout(title = 'xAGperChance vs Chances/90 (MLS + USL CMs)',
xaxis = list(title = "Expected Contributions Per Chance created (xAGperChance)",
linecolor = toRGB("black"),zeroline = FALSE,showgrid=FALSE),
paper_bgcolor='rgb(252, 230, 248)',
plot_bgcolor='rgb(230, 239, 255)',
yaxis = list(title = "Chances Created Per Match (Chances/90)",
linecolor = toRGB("black"),zeroline = FALSE,showgrid=FALSE))
radarCM = function(data)
{
#print(data)
#plot.new()
par(mar = c(1,1,1.3,1))
#par(mai = c(1,1,1,1))
par(mfrow=c(11,4))
plot.new()
plot.new()
plot.new()
plot.new()
for(i in 1:nrow(data))
{
data1 <- rbind(apply(data[c("xAGper90","chancesper90","xAGperChance","Pass.","Intper90","TklAcc","Recovery","X1v1.")],2,max) ,
apply(data[c("xAGper90","chancesper90","xAGperChance","Pass.","Intper90","TklAcc","Recovery","X1v1.")],2,min) ,
data[i,c("xAGper90","chancesper90","xAGperChance","Pass.","Intper90","TklAcc","Recovery","X1v1.")])
#print(data$player[i])
#print(data1)
radarchart(data1, axistype= 1 ,
# Orange for Domestic , Blue for International Players
pcol = ifelse(data$Country[i]=="USA",rgb(0.98,0.55,0.01,0.9),rgb(0.1,0.1,0.9,0.7)),
pfcol = ifelse(data$Country[i]=="USA",rgb(0.98,0.55,0.01,0.3),rgb(0.1,0.2,0.9,0.3)),
vlabels = c("xAG/90","Chn/90","xAG/Chn","PassAcc","Int/90","TklAcc","Rec","1v1Acc"),
#custom polygon
plwd=2 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="brown", caxislabels= NULL, calcex= 0.6,#, cglwd=0.2,
title = ifelse(data$league[i]=="MLS (USA)",
paste(data$player[i],"(MLS)"),
paste(data$player[i],"(USL)")),
#custom labels
vlcex=1 , cex.main= 1.2,centerzero = TRUE
)
}
mtext("Central Midfielders - Radar Chart",side=3,outer=TRUE,padj=5,cex = 3)
}
CM = rbind(usl[usl$Position=="Central Midfielder",c("player","league","Country","xAGper90","chancesper90","xAGperChance","Pass.","Intper90","TklAcc","Recovery","X1v1.")]
,mls[mls$Position.x=="Central Midfielder",c("player","league","Country","xAGper90","chancesper90","xAGperChance","Pass.","Intper90","TklAcc","Recovery","X1v1.")])
radarCM(CM)
radarRB = function(data)
{
#print(data)
#plot.new()
par(mar = c(1,1,1.3,1))
#par(mai = c(1,1,1,1))
par(mfrow=c(7,4))
plot.new()
plot.new()
plot.new()
plot.new()
for(i in 1:nrow(data))
{
data1 <- rbind(apply(data[c("xAGper90","xAGperChance","chancesper90","Recovery","TklAcc","Intper90","X1v1.")],2,max) ,
apply(data[c("xAGper90","xAGperChance","chancesper90","Recovery","TklAcc","Intper90","X1v1.")],2,min) ,
data[i,c("xAGper90","xAGperChance","chancesper90","Recovery","TklAcc","Intper90","X1v1.")])
#print(data$player[i])
#print(data1)
radarchart(data1, axistype= 1 ,
# Orange for Domestic , Blue for International Players
pcol = ifelse(data$Country[i]=="USA",rgb(0.98,0.55,0.01,0.9),rgb(0.1,0.1,0.9,0.7)),
pfcol = ifelse(data$Country[i]=="USA",rgb(0.98,0.55,0.01,0.3),rgb(0.1,0.2,0.9,0.3)),
#custom polygon
plwd=2 ,
vlabels = c("xAG/90","xAG/Chn","Chn/90","Rec.","TklAcc","Int/90","1v1Acc"),
#custom the grid
cglcol="grey", cglty=1, axislabcol="brown", caxislabels= NULL, calcex= 0.6,#, cglwd=0.2,
#custom labels
vlcex=1 ,
title = ifelse(data$league[i]=="MLS (USA)",
paste(data$player[i],"(MLS)"),
paste(data$player[i],"(USL)")),
cex.main= 1.2,centerzero = TRUE
)
}
mtext("Right Back - Radar Chart",side=3,outer=TRUE,padj=5,cex = 3)
}
RB = rbind(usl[usl$Position=="Right Back",c("player","league","Country","xAGper90","xAGperChance","chancesper90","Intper90","TklAcc","Recovery","X1v1.")]
,mls[mls$Position.x=="Right Back",c("player","league","Country","xAGper90","xAGperChance","chancesper90","Intper90","TklAcc","Recovery","X1v1.")])
radarRB(RB)
Read “Preference (International/Domestic) - Playing Style”
1.Moumbagna (Intl) - All rounded
2.M Toye (Dom) - All rounded
3.N Daley (Intl) - All rounded
1.Blessing (Dom) - All rounded
2.Lletget (Dom) - Playmaker
3.Jorge Hernandez (Dom) - Attack
1.H Afful (Intl) - Defensive
2.K Rosenberry (Dom) - Defensive
3.R Laryea (Intl) - All rounded
CF : Moumbagna - USL - International Player
CM : Blessing - MLS - Domestic Player
RB : Rosenberry - MLS - Domestic Player